<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view(TPL_FOLDER."header");?>
<link rel="stylesheet" type="text/css" href="{root_path}js/jquery/hiAlert/jquery.hiAlerts.css">
<script type="text/javascript" src="{root_path}js/jquery/hiAlert/jquery.hiAlerts-min.js"></script>
<div style="padding:10px">
<div class="ui-tx-nav-bar"><a href="<?php echo site_url(CTL_FOLDER.'home');?>">首页</a><?php echo $nav;?> </div>
<table width="100%" cellpadding="5" cellspacing="0" class="ui-tx-tablelist">
  <thead>
    <tr>
      <th width="22%" align="left">产品图片</th>
      <th width="31%" align="left">产品名称</th>
      <th width="13%" align="left">订购数量</th>
      <th width="15%" align="left">产品单价(￥)</th>
      <th width="12%" align="left">小计(￥)</th>
      <th width="7%" align="left">操作</th>
    </tr>
  </thead>
  <tbody>
    <?php 
		if($cart_data){
		foreach($cart_data as $row){ 
	?>
    <tr>
      <td><a target="_blank" href="<?php echo site_url(CTL_FOLDER.'product/detail/'.$row->product_id);?>" title="<?php echo $row->title;?>"><img src="{tpl_path}images/common/loading.gif" title="<?php echo $row->title;?>" alt="<?php echo $row->title;?>" rel="<?php echo get_real_path($row->pic_path);?>" class="loading_60"></a></td>
      <td style='text-align:left'><a target="_blank" href="<?php echo site_url(CTL_FOLDER.'product/detail/'.$row->product_id);?>" title="<?php echo $row->title;?>"><?php echo $row->title;?></a></td>
      <td><input type="text" class="ui-tx-input cart_quantity" rel="<?php echo $row->id;?>" value="<?php echo $row->quantity;?>" size="3" maxlength="10" /></td>
      <td><?php echo $row->price;?></td>
      <td><?php echo $row->subtotal;?></td>
      <td><a href="javascript:del_cart(<?php echo $row->id;?>)">删除</a></td>
    </tr>
    <?php
	}
	?>
    <tr>
      <td><a href="<?php echo site_url(CTL_FOLDER.'product');?>"><img src="{tpl_path}images/common/back.jpg" style="vertical-align:middle" /> 返回继续挑选</a></td>
      <td><a href="javascript:clear_cart();"><img src="{tpl_path}images/common/clear.jpg" style="vertical-align:middle" /> 一键清空</a></td>
      <td>&nbsp;</td>
      <td align="right"><img src="{tpl_path}images/common/currency_yuan.jpg" style="vertical-align:middle" /> 总额：</td>
      <td id="totalprice"><?php echo $total_price;?></td>
      <td>&nbsp;</td>
    </tr>
    <?php }else{?>
    <tr>
      <td colspan="6" align="center"><font style="color:#FF0000">您还没有挑选任何产品</font><br /><br /><a href="<?php echo site_url(CTL_FOLDER.'product');?>">现在去挑选</a></td>
    </tr>
    <? }?>
  </tbody>
</table>
<?php if($cart_data){?>
<fieldset>
<legend><img src="{tpl_path}images/common/reg_icon.png" style="vertical-align:middle" /> 填写订单资料</legend>
<form method="post" action="<?php echo site_url(CTL_FOLDER.'order/save_order');?>">
  <table width="100%" border="0" cellspacing="5" cellpadding="5">
    <tr>
      <th width="20%" align="right"><font style="color:#FF0000">*</font>联系人：</th>
      <td width="80%"><input type="text" size="20" name="true_name" class="ui-tx-input" maxlength="50" dataType="Require" msg="该项必填" /></td>
    </tr>
    <tr>
      <th align="right"><font style="color:#FF0000">*</font>电子邮箱：</th>
      <td><input type="text" size="20" name="email" class="ui-tx-input" maxlength="50" dataType="Email" msg="邮箱格式有误" /></td>
    </tr>
    <tr>
      <th align="right"><font style="color:#FF0000">*</font>电 话：</th>
      <td><input type="text" size="20" name="tel" class="ui-tx-input" maxlength="50" dataType="Require" msg="该项必填" /></td>
    </tr>
    <tr>
      <th align="right"><font style="color:#FF0000">*</font>地 址：</th>
      <td><input type="text" name="address" class="ui-tx-input" maxlength="200" size="65" datatype="Require" msg="该项必填" /></td>
    </tr>
    <tr>
      <th align="right">订单附言：</th>
      <td><input type="text" size="65" name="detail" class="ui-tx-input" maxlength="100"  /></td>
    </tr>
    <tr>
      <th align="right"><font style="color:#FF0000">*</font>验证码：</th>
      <td><input name="validate_code" onfocus="get_validate_code('validate_html')" size="5" maxlength="4" id="validate_code" type="text" class="ui-tx-input" dataType="Require" msg="该项必填"/>
        <span id="validate_html"></span></td>
    </tr>
    <tr>
      <th></th>
      <td><input type="button" onclick="subForm(this.form,this)" value="提交订单" class="ui-tx-button2" style="width:80px"></td>
    </tr>
  </table>
</form>
<div class="clear"></div>
</fieldset>
<script language="javascript">
$(function(){
	$(".loading_60").each(function(){
		LoadImage($(this),$(this).attr("rel"),60);
	});
	$(".cart_quantity").change(function(){
		update_quantity($(this));
	});
});
function update_quantity(ob)
{
	var quantity=ob.val();
	var rd_id=ob.attr("rel");
	var subtotal = ob.parent().siblings(":eq(3)");
	if(!is_numeric(quantity))
	{
		alert("购买数量有误，请重新填写");
		return false;
	}
	hiOverAlert("<span id='showMsg'><img src='"+pic_loading_path+"' border='0' /> 数据处理中，请稍等...</span>",0);
	$.ajax({
		type:"POST",
		url:"<?php echo site_url(CTL_FOLDER.'order/update_cart');?>",
		data:"rd_id="+rd_id+"&quantity="+quantity,
		dataType:"json",
		success:function(msg){
			if(msg!=0)
			{
				$("#showMsg").html("订购数量更新成功");
				setTimeout(function(){unhiOverAlert();}, 2000);
				$("#totalprice").html(msg.total);
				subtotal.html(msg.subtotal);
			}
			else
			{
				$("#showMsg").html("订购数量更新失败");
				setTimeout(function(){unhiOverAlert(); }, 2000);
			}
		},
		error:function(){
			$("#showMsg").html("数据处理失败");
			setTimeout(function(){unhiOverAlert();}, 2000);
		}
	});
}
function del_cart(id)
{
	if(!is_numeric(id))
	{
		alert("提交的数据有误");
		return ;
	}
	if(!confirm('确定要删除该产品吗？')) return ;
	hiOverAlert("<span id='showMsg'><img src='"+pic_loading_path+"' border='0' /> 数据处理中，请稍等...</span>",0);
	$.ajax({
		type:"POST",
		url:"<?php echo site_url(CTL_FOLDER.'order/del_cart');?>",
		data:"rd_id="+id,
		success:function(msg){
			if(msg!=0)
			{
				$("#showMsg").html("该产品删除成功");
				setTimeout(function(){unhiOverAlert();document.location.reload();}, 2000);
			}
			else
			{
				$("#showMsg").html("该产品删除失败");
				setTimeout(function(){unhiOverAlert(); }, 2000);
			}
		},
		error:function(){
			$("#showMsg").html("数据处理失败");
			setTimeout(function(){unhiOverAlert(); }, 2000);
		}
	});
}
function clear_cart()
{
	if(!confirm('确定要清空已挑选的所有产品吗？')) return ;
	hiOverAlert("<span id='showMsg'><img src='"+pic_loading_path+"' border='0' /> 数据处理中，请稍等...</span>",0);
	$.ajax({
		type:"POST",
		url:"<?php echo site_url(CTL_FOLDER.'order/clear_cart');?>",
		data:"rd_id=ff",
		success:function(msg){
			if(msg!=0)
			{
				$("#showMsg").html("清除成功");
				setTimeout(function(){unhiOverAlert();document.location.reload();}, 2000);
			}
			else
			{
				$("#showMsg").html("清除失败");
				setTimeout(function(){unhiOverAlert(); }, 2000);
			}
		},
		error:function(){
			$("#showMsg").html("数据处理失败");
			setTimeout(function(){unhiOverAlert(); }, 2000);
		}
	});
}
</script>
<?php }?>
</div>
<?php $this->load->view(TPL_FOLDER."footer");?>
